package com.study.operFile;

import com.spring.annotation.importanno.Import11;
import org.junit.Test;

import java.io.*;
import java.util.Arrays;

/**
 * @author ：HBZ
 * @date ：Created in 2020/12/29 16:09
 * @description：
 * @modified By：
 */

public class TestFile {
    @Test
    public void listFile(){
        String filename="E:"+ File.separator+"temp";
        File file=new File(filename);
        String[] list = file.list();
        System.out.println("文件总数："+list.length);
        Arrays.stream(list).forEach(System.out::println);
        System.out.println("---------------------");
        File[] files = file.listFiles();
        Arrays.asList(files).forEach((file1)-> System.out.println( file1.getAbsolutePath()));
        System.out.println("---------------------");
        // 或者
        Arrays.asList(files).forEach(System.out::println);
    }
    @Test
    public void fileInput(){
        String filename="E://temp//1.txt";
        File file=new File(filename);
        try {
            InputStream inputStream=new FileInputStream(file);
            byte []bytes=new byte[(int)file.length()];
            int len=inputStream.read(bytes);
            System.out.println(new String(bytes,0,len));
            System.out.println(new String(bytes));
            inputStream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
